//
//  NSString+MYStringTools.m
//  DEMO--MYTools
//
//  Created by 范名扬 on 15/1/15.
//  Copyright (c) 2015年 范名扬. All rights reserved.
//

#import "NSString+MYStringTools.h"

@implementation NSString (MYStringTools)

- (BOOL)isContainString:(NSString *)string
{
    NSRange range = [self rangeOfString:string];
    if (range.length) {
        return YES;
    }else{
        return NO;
    }
}

- (instancetype)replaceString:(NSString *)aString withString:(NSString *)bString
{
    NSRange range = [self rangeOfString:aString];
    NSUInteger loc = range.location;
    NSUInteger len = range.length;
    if (!len) {
        return nil;
    }
    NSString *preStr = [self substringToIndex:loc];
    NSString *sufStr = [self substringFromIndex:loc + len];
    return [NSString stringWithFormat:@"%@%@%@",preStr,bString,sufStr];
}

- (instancetype)getPreStringInSting:(NSString *)string
{
    NSRange range = [self rangeOfString:string];
    return [self substringToIndex:range.location];
}

- (instancetype)getSufStringInSting:(NSString *)string
{
    NSRange range = [self rangeOfString:string];
    return [self substringFromIndex:range.location + range.length];
}

@end
